#include <gtest/gtest.h>
#include <thread>
#include "MmapSHMObject.h"
#include "SHMQueue.h"
#include "Util.h"

typedef xncc::msg::SHMQueue TestQueue;
class SHMQueueTestSuite : public ::testing::Test
{
  public:
    static void SetUpTestSuite()
    {
        const auto size = TestQueue::GetMemorySize(4096);
        shm_producer    = new xncc::shared::MmapSHMObject(xncc::shared::SHM_FILE_MODE::OPENORCREATE,
                                                          xncc::shared::SHM_MODE::READ_WRITE, "test_queue",
                                                          static_cast<long long>(size));

        while (!xncc::shared::FileBusi::exists("/dev/shm/test_queue")) {
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
        }

        shm_consumer =
            new xncc::shared::MmapSHMObject(xncc::shared::SHM_FILE_MODE::OPEN, xncc::shared::SHM_MODE::READ_ONLY,
                                            "test_queue", static_cast<long long>(size));

        shm_queue_producer = TestQueue::createProducerQueue(size, shm_producer->getAddress());

        shm_queue_consumer = TestQueue::createConsumerQueue(shm_consumer->getAddress());
    }
    static void TearDownTestSuite()
    {
        delete shm_producer;
        delete shm_consumer;
    }
    virtual void SetUp()
    {
    }
    virtual void TearDown()
    {
    }
    static TestQueue*                   shm_queue_producer;
    static TestQueue*                   shm_queue_consumer;
    static xncc::shared::MmapSHMObject* shm_producer;
    static xncc::shared::MmapSHMObject* shm_consumer;
};